#!/bin/sh
# - nr_1Mfiles
# - nr_1Gfiles

## Author: Theodore Ts'o <tytso@mit.edu>
##
## For future reference, there are a couple of things that are of
## interest to ext4 developers when trying to create repro's:
##
## 1)  The use of mounting with ext2 to speed up the setup.
##
## 2)  The first two "seq ... | xargs ..." commands to create a very
## fragmented file system.
##
## 3) Using a 1k block size file system to stress the extent tree code
## and htree directory (since its easier to make larger tree structure).
##
## 4)  The use of the mount option commit=10000 to test what happens when
## the journal is full (without using a nice, fast device such as RAID array
## or without burning write cycles on an expensive flash device.)
##
## https://patchwork.kernel.org/patch/1333461/

. $LKP_SRC/lib/reproduce-log.sh

[ $nr_partitions -ge 1 ] || exit
partition=${partitions%% *}

[ -n "$nr_1Mfiles" ] || nr_1Mfiles=21000
[ -n "$nr_1Gfiles" ] || nr_1Gfiles=103

mnt=/mnt
log_cmd mkdir -p $mnt

log_cmd mke2fs -t ext4 -b 1024 -J size=1 -q $partition
log_cmd mount -t ext2 $partition $mnt 2>/dev/null ||
log_cmd mount -t ext4 $partition $mnt             || die
log_cmd mkdir $mnt/a
log_cmd cd $mnt/a
log_echo "seq 1 $nr_1Mfiles | xargs -n 1 fallocate -l 1m"
seq 1 $nr_1Mfiles | xargs -n 1 fallocate -l 1m || die
log_echo "seq 1 2 $nr_1Mfiles | xargs /bin/rm"
seq 1 2 $nr_1Mfiles | xargs /bin/rm || die
log_cmd mkdir $mnt/b
log_cmd cd $mnt/b
log_echo "seq 1 $nr_1Gfiles | xargs -n 1 fallocate -l 1g"
seq 1 $nr_1Gfiles | xargs -n 1 fallocate -l 1g || die
log_cmd cd /
log_cmd umount $mnt
log_cmd mount -t ext4 -o commit=10000 $partition $mnt || die
log_cmd rm -rf $mnt/b

echo "$testcase pass"
